<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/06/02
// +----------------------------------------------------------------------

namespace app\erp\model;

use think\Db;
use think\Model;

/**
 * 门店-人员管理
 * @package app\erp\model
 */
class ErpStoreUser extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_erp_store_user';

    /**
     * 查询
     *
     */
    public function getStoreUser($store_id)
    {
        $result = $this->table
            ->where('store_id','=',$store_id)
            ->order('create_time desc')
            ->paginate();
        return $result;
    }


    /**
     * 添加数据
     * @param user_name 	            string  用户名
     * @param password 		        string  密码
     * @param nick_name 		        string  昵称
     * @param store_id 		        int  门店id
     * @author dou<51779987@qq.com>
     * @return array_out(password, message, (int)id)
     */
    public function addData($user_name, $password, $nick_name, $store_id){
        $data['user_name']     = $user_name;
        $data['password']      = $password;
        $data['nick_name']   = $nick_name;
        $data['store_id']      = $store_id;
        $res = $this -> isUpdate(false) ->data($data, true) -> save();
        if($res){
            return array_out(200, 'success', $this -> id);
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	
	/**
     * 编辑数据
     * @param id 	                string  人员id
     * @param user_name 	            string  用户名
     * @param password 		        string  密码
     * @param nick_name 		        string  昵称
     * @author dou<51779987@qq.com>
     * @return array_out(password, message, (int)id)
     */
	public function editData($id, $user_name, $password, $nick_name){
		$map = [];
		$map['id'] = $id;
		
		$data = [];
		$data['user_name'] 		= $user_name;
        $data['password'] 		= $password;
        $data['nick_name'] 	    = $nick_name;
        $res = $this ->update($data, $map);

		if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
	}
	
	/**
     * 删除数据
     * @param int $id
     * @author dou<51779987@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
}
